package eip.chapter5.sequence.util;

import java.util.ArrayList;
import java.util.Random;

import eip.chapter5.sequence.Bill;
import eip.chapter5.sequence.BillIdentifierWrapper;
import eip.chapter5.sequence.CheckoutBill;

public class BillingCalculator {

	public static CheckoutBill calculateBilling(ArrayList<BillIdentifierWrapper> billWrapperList) {
		CheckoutBill checkoutBill = new CheckoutBill();
		checkoutBill.setTotalBillID(String.valueOf(new Random().nextInt(1000000000)));
		ArrayList<Bill> billList = new ArrayList<Bill>();
		double totalAmount = 0.0d;
		for(BillIdentifierWrapper billWrapper : billWrapperList) {
			Bill bill = billWrapper.getBill();
			checkoutBill.setGuestName(bill.getGuestName());
			totalAmount += bill.getAmount();
			billList.add(bill);
		}
		checkoutBill.setBillList(billList);
		checkoutBill.setTotalAmount(totalAmount);
		return checkoutBill;
	}
	
}
